<template>
  <div id="AccessControlApplication">
    <div class="dev-nav">
      <p>门禁申请</p>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>出入管理</el-breadcrumb-item>
        <el-breadcrumb-item>权限管理</el-breadcrumb-item>
        <el-breadcrumb-item>门禁申请</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="search">
      <el-input v-model="input1" placeholder="申请人员"></el-input>
      <el-input v-model="input2" placeholder="手机号码"></el-input>
      <el-input v-model="input3" placeholder="证件号码"></el-input>
      <!-- <el-input v-model="input" placeholder="房屋位置"></el-input> -->
      <el-select v-model="houseValue" filterable placeholder="房屋位置">
        <el-option
          v-for="item in houseOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
      <el-select v-model="appStatusValue" filterable placeholder="申请状态">
        <el-option
          v-for="item in appStatusOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>

      <!-- 日历 -->
      <div class="block">
        <!-- <span class="demonstration">默认</span> -->
        <el-date-picker
          class="block-content"
          v-model="value1"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </div>
      <!-- 查询 -->
      <el-button
        type="success"
        style="background-color: #0bb197"
        @click="inquire"
      >
        <i class="el-icon-search"></i>
        查询</el-button
      >
      <el-button
        type="success"
        plain
        style="margin-right: 0px"
        class="reset"
        @click="reset"
      >
        <i class="el-icon-refresh"></i>
        重置</el-button
      >
    </div>
    <!-- 表格内容 -->
    <div class="dev-content">
      <p>查询结果列表</p>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="applyId" label="序号" width="50" align="center">
        </el-table-column>
        <el-table-column
          prop="applyPerson"
          label="申请人员"
          width="90"
          align="center"
        >
        </el-table-column>
        <el-table-column label="性别" width="50" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.gender == 0 ? "女" : "男" }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="手机号码" align="center">
        </el-table-column>
        <el-table-column prop="idCard" label="证件号码" align="center">
        </el-table-column>
        <el-table-column prop="home" label="绑定房屋" align="center">
        </el-table-column>
        <el-table-column label="人员类型" width="80" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.personType == 2">业主</span>
            <span v-if="scope.row.personType == 1">家庭成员</span>
            <span v-if="scope.row.personType == 0">租户</span>
          </template>
        </el-table-column>
        <el-table-column width="80" label="人脸照片" align="center">
          <template slot-scope="scope">
            <img :src="scope.row.facePhoto" />
          </template>
        </el-table-column>
        <el-table-column label="申请时间" align="center">
          <template slot-scope="scope">
            <span>{{ timeTrans(scope.row.applyTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="applyStatus" label="申请状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.applyStatus == 0">待审核</span>
            <span v-if="scope.row.applyStatus == 1">审核已通过</span>
            <span v-if="scope.row.applyStatus == 2">审核未通过</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="200" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.applyStatus == 1"></span>
            <el-button
              v-else
              @click="userAuditing(scope.row)"
              type="text"
              size="small"
              style="color: #0bb197"
              >用户审核</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :background="true"
        class="msg-pagination-container"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="count"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
    <!-- 用户审核弹窗 -->
    <el-dialog :visible.sync="dialogVisible" width="30%" center>
      <span center style="display: block; text-align: center"
        >是否确认用户{{ this.userAuditingText }}门禁申请认证？</span
      >
      <span slot="footer" class="dialog-footer" center="true">
        <el-button @click="reviewRejection" style="background-color: #ccc"
          >审核驳回</el-button
        >
        <el-button
          type="primary"
          @click="approve"
          style="background-color: #0bb197"
          >审核通过</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import time from "../utils/time";
export default {
  mixins: [time],
  data() {
    return {
      page: 1,
      count: 5,
      total: 1,
      input1: "",
      input2: "",
      input3: "",
      tableData: [],
      //  日历
      value1: [],
      startTime: "",
      endTime: "",
      //   申请状态
      appStatusOptions: [
        {
          value: 0,
          label: "待审核",
        },
        {
          value: 1,
          label: "审核已通过",
        },
        {
          value: 2,
          label: "审核未通过",
        },
      ],
      appStatusValue: "",
      //   房屋位置
      houseOptions: [],
      houseValue: "",
      // 审核弹窗
      dialogVisible: false,
      // 审核弹窗内容
      userAuditingText: "",
      approveApplyId: "",
    };
  },
  methods: {
    handleSizeChange(val) {
      this.count = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getData();
    },
    // 渲染
    getData() {
      this.value1[0] && (this.startTime = this.timeTrans(this.value1[0]));
      this.value1[1] && (this.endTime = this.timeTrans(this.value1[1]));
      this.$axios({
        url: "/smart/access-control/list",
        method: "get",
        params: {
          pageNum: this.page,
          pageSize: this.count,
          name: this.input1,
          phone: this.input2,
          idCard: this.input3,
          homeLocation: this.houseValue,
          status: this.appStatusValue,
          startTime: this.startTime,
          endTime: this.endTime,
        },
      }).then(({ data }) => {
        // console.log("啦啦啦啦", data);
        if (data.code == 2000) {
          this.tableData = data.data.list;
          this.total = data.data.total;
        } else {
          this.$message.error("数据加载失败！");
        }
      });
    },
    // 查询
    inquire() {
      // alert("还没有查询接口");
      this.getData();
    },
    // 重置
    reset() {
      this.input1 = "";
      this.input2 = "";
      this.input3 = "";
      this.houseValue = [];
      this.appStatusValue = [];
      this.value1 = [];
      this.startTime = "";
      this.endTime = "";
      this.getData();
      this.$message.success("重置成功");
    },
    // 操作里的用户审核
    userAuditing(items) {
      // console.log(12);
      // console.log(items);
      this.dialogVisible = true;
      this.userAuditingText = items.applyId;
    },

    // 渲染搜索中的内容  房屋位置
    getSearch() {
      this.$axios({
        url: "/smart/access-control/list",
        methods: "get",
        params: {
          pageNum: this.page,
          pageSize: this.count,
        },
      }).then(({ data }) => {
        data.homeLocations.forEach((v, i) => {
          let item = {
            value: v,
            label: v,
          };
          this.houseOptions.push(item);
        });
      });
    },
    // 审核通过
    approve() {
      this.dialogVisible = false;
      this.$axios({
        url: "/smart/access-control/edit",
        method: "put",
        data: {
          applyId: this.userAuditingText,
          applyStatus: 1,
        },
      }).then(({ data }) => {
        if (data.code == 2000) {
          this.getData();
          this.$message.success("审核已通过");
        }
      });
    },
    // 审核驳回
    reviewRejection() {
      this.dialogVisible = false;
      this.$axios({
        url: "/smart/access-control/edit",
        method: "put",
        data: {
          applyId: this.userAuditingText,
          applyStatus: 2,
        },
      }).then(({ data }) => {
        if (data.code == 2000) {
          this.getData();
          this.$message.success("审核已驳回");
        }
      });
    },
  },
  mounted() {
    this.getData();
    this.getSearch();
  },
};
</script>


<style lang="less" scoped>
#AccessControlApplication {
  padding: 20px;
  //   background-color: #f3f3f4;
  //   border: 1px solid red;
  .dev-nav {
    display: flex;
    justify-content: space-between;
  }
  p {
    font-size: 18px;
    margin: 0;
  }
  .search {
    margin: 20px 0px;
    padding: 20px 15px;
    display: flex;
    align-items: center;
    background-color: white;
    border-radius: 8px;
    .reset {
      background-color: white;
      color: #c0c4cc;
      border: 1px solid #c0c4cc;
    }
    .reset:hover {
      color: #0bb197;
    }
    .el-input {
      width: 150px;
      margin-right: 10px;
    }
    .el-select {
      margin-right: 10px;
    }
    .block {
      margin-right: 10px;
      .block-content {
        width: 310px;
      }
    }
    .el-button {
      padding: 10px 15px;
      margin-left: 0px;
      margin-right: 20px;
    }
  }
  .dev-content {
    padding: 20px 15px;
    padding-bottom: 30px;
    background-color: white;
    border-radius: 8px;
    p {
      font-size: 16px;
      margin-bottom: 10px;
    }
    .el-pagination {
      text-align: end;
      margin-top: 20px;
    }
    .el-table-column {
      img {
        width: 40px;
        height: 40px;
        border-radius: 20px;
      }
    }
  }
}
</style>
<style>
.msg-pagination-container.is-background .el-pager li:not(.disabled).active {
  /*当前选中页数的样式进行修改*/
  background-color: #0bb197;
  color: #fff;
}
.cell > img {
  width: 50px;
  height: 100%;
}
</style>